package com.skyz.wrap.utils;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;

import com.hjq.toast.ToastUtils;

public class TiktokUtil {
    private TiktokUtil(){

    }
    private static TiktokUtil instance = new TiktokUtil();

    public static TiktokUtil getInstance(){
        return  instance;
    }


    private void jump(Activity activity,String tikTokUrl){
        Intent intent =new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(tikTokUrl)) ;
        ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if (resolveInfo != null){
            activity.startActivity(intent);
        }else{
            ToastUtils.show("请安装抖音");
        }
    }

    /**
     * 跳转作者页面
     * @param activity
     * @param uid 用户抖音ID
     */
    public void jumpByUserId(Activity activity,String uid){
        String url = "snssdk1128://user/profile/"+uid;
        jump(activity,url);
    }

    /**
     * 跳转作品页面
     * @param activity
     * @param awemeId 作品ID
     */
    public void jumpByAwemeID(Activity activity,String awemeId){
        String url = "snssdk1128://aweme/detail/"+awemeId;
        jump(activity,url);
    }

}
